package com.liit.console.controller.front;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.liit.console.filter.WebContext;
import com.liit.module.entity.Files;
import com.liit.module.entity.Product;
import com.liit.module.frame.utils.ConfigUtil;
import com.liit.module.frame.utils.Const;
import com.liit.module.frame.utils.FileUtil;
import com.liit.module.frame.utils.ValidatorUtils;
import com.liit.module.frame.utils.page.Pagination;
import com.liit.module.service.DictService;
import com.liit.module.service.FilesService;
import com.liit.module.service.ProductCategoryService;
import com.liit.module.service.ProductService;

/**
 * @author dingweibo
 * @Title: ProductController.java
 * @Description: 产品相关
 * @date 2015年12月15日
 */
@Controller
@RequestMapping(value = "/product")
public class ProductController {

	private Logger logger = Logger.getLogger(getClass());

	@Resource
	ProductService productService;

	@Resource
	FilesService filesService;

	@Resource
	DictService dictService;

	@Resource
	ProductCategoryService productCategoryService;

	/**
	 * 添加产品
	 * 
	 * @param product
	 * @param pagination
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/list")
	public String list(Product product, Pagination pagination) throws Exception {
		Map<String, Object> result = productService.listPage(pagination, product);
		List<Product> list = (List<Product>) result.get("list");
		BeanUtils.copyProperties(result.get("page"), pagination);
		Map<String, Map<String, Files>> imgMap = new HashMap<String, Map<String, Files>>();
		for (Product p : list) {
			Map<String, Files> row = new HashMap<String, Files>();
			Files imgLogoPath = filesService.selectById(p.getImgLogo());
			imgLogoPath.setPath(FileUtil.getUrl(imgLogoPath));
			row.put("imgLogo", imgLogoPath);
			imgMap.put(p.getId().toString(), row);
		}
		WebContext.setAttribute("imgMap", imgMap);
		WebContext.setAttribute("list", list);
		WebContext.setAttribute(Const.PAGINATION, pagination);
		WebContext.setAttribute("productType", dictService.selectByColumn(Const.PRODUCT_TYPE));
		WebContext.setAttribute("productCategory", productCategoryService.selectCategory(null));
		return "/front/productList";
	}

	/**
	 * 添加产品
	 * 
	 * @return
	 */
	@RequestMapping(value = "/add")
	public String add(Integer id) {
		WebContext.setAttribute("productType", dictService.selectByColumn(Const.PRODUCT_TYPE));
		WebContext.setAttribute("productCategory", productCategoryService.selectCategory(Const.STATUS_ENABLED));
		if (id != null) {
			Product product = productService.selectById(id);
			WebContext.setAttribute("product", product);
			WebContext.setAttribute("imgLogoPath", FileUtil.getUrl(filesService.selectById(product.getImgLogo())));
			if (product.getImgOne() != null) {
				WebContext.setAttribute("imgOnePath", FileUtil.getUrl(filesService.selectById(product.getImgOne())));
			}
			if (product.getImgTwo() != null) {
				WebContext.setAttribute("imgTwoPath", FileUtil.getUrl(filesService.selectById(product.getImgTwo())));
			}
			if (product.getImgThree() != null) {
				WebContext.setAttribute("imgThreePath", FileUtil.getUrl(filesService.selectById(product.getImgThree())));
			}
			if (product.getImgFour() != null) {
				WebContext.setAttribute("imgFourPath", FileUtil.getUrl(filesService.selectById(product.getImgFour())));
			}
			if (product.getImgFive() != null) {
				WebContext.setAttribute("imgFivePath", FileUtil.getUrl(filesService.selectById(product.getImgFive())));
			}
			if (product.getImgSix() != null) {
				WebContext.setAttribute("imgSixPath", FileUtil.getUrl(filesService.selectById(product.getImgSix())));
			}
			if (product.getImgSeven() != null) {
				WebContext.setAttribute("imgSevenPath", FileUtil.getUrl(filesService.selectById(product.getImgSeven())));
			}
			if (product.getImgEight() != null) {
				WebContext.setAttribute("imgEightPath", FileUtil.getUrl(filesService.selectById(product.getImgEight())));
			}
			if (product.getImgNine() != null) {
				WebContext.setAttribute("imgNinePath", FileUtil.getUrl(filesService.selectById(product.getImgNine())));
			}
			if (product.getImgTen() != null) {
				WebContext.setAttribute("imgTenPath", FileUtil.getUrl(filesService.selectById(product.getImgTen())));
			}
			if (product.getImgEleven() != null) {
				WebContext.setAttribute("imgElevenPath", FileUtil.getUrl(filesService.selectById(product.getImgEleven())));
			}
			if (product.getImgTwelve() != null) {
				WebContext.setAttribute("imgTwelvePath", FileUtil.getUrl(filesService.selectById(product.getImgTwelve())));
			}
			if (product.getImgThirteen() != null) {
				WebContext.setAttribute("imgThirteenPath", FileUtil.getUrl(filesService.selectById(product.getImgThirteen())));
			}
			if (product.getImgFourteen() != null) {
				WebContext.setAttribute("imgFourteenPath", FileUtil.getUrl(filesService.selectById(product.getImgFourteen())));
			}
			if (product.getImgFifteen() != null) {
				WebContext.setAttribute("imgFifteenPath", FileUtil.getUrl(filesService.selectById(product.getImgFifteen())));
			}
			if (product.getImgSixteen() != null) {
				WebContext.setAttribute("imgSixteenPath", FileUtil.getUrl(filesService.selectById(product.getImgSixteen())));
			}
			if (product.getImgSeventeen() != null) {
				WebContext.setAttribute("imgSeventeenPath", FileUtil.getUrl(filesService.selectById(product.getImgSeventeen())));
			}
			if (product.getImgEighteen() != null) {
				WebContext.setAttribute("imgEighteenPath", FileUtil.getUrl(filesService.selectById(product.getImgEighteen())));
			}
			if (product.getImgNineteen() != null) {
				WebContext.setAttribute("imgNineteenPath", FileUtil.getUrl(filesService.selectById(product.getImgNineteen())));
			}
			if (product.getImgTwenty() != null) {
				WebContext.setAttribute("imgTwentyPath", FileUtil.getUrl(filesService.selectById(product.getImgTwenty())));
			}
		}
		return "/front/productAdd";
	}

	/**
	 * 保存产品
	 * 
	 * @param product
	 * @param id
	 * @return
	 * @throws IOException
	 * @throws IllegalStateException
	 */
	@RequestMapping("/save")
	public String save(Product product, @RequestParam("imgLogoFile") MultipartFile imgLogoFile, @RequestParam("imgOneFile") MultipartFile imgOneFile,
			@RequestParam("imgTwoFile") MultipartFile imgTwoFile, @RequestParam("imgThreeFile") MultipartFile imgThreeFile, @RequestParam("imgFourFile") MultipartFile imgFourFile,
			@RequestParam("imgFiveFile") MultipartFile imgFiveFile, @RequestParam("imgSixFile") MultipartFile imgSixFile, @RequestParam("imgSevenFile") MultipartFile imgSevenFile,
			@RequestParam("imgEightFile") MultipartFile imgEightFile, @RequestParam("imgNineFile") MultipartFile imgNineFile, @RequestParam("imgTenFile") MultipartFile imgTenFile,
			@RequestParam("imgElevenFile") MultipartFile imgElevenFile, @RequestParam("imgTwelveFile") MultipartFile imgTwelveFile,
			@RequestParam("imgThirteenFile") MultipartFile imgThirteenFile, @RequestParam("imgFourteenFile") MultipartFile imgFourteenFile,
			@RequestParam("imgFifteenFile") MultipartFile imgFifteenFile, @RequestParam("imgSixteenFile") MultipartFile imgSixteenFile,
			@RequestParam("imgSeventeenFile") MultipartFile imgSeventeenFile, @RequestParam("imgEighteenFile") MultipartFile imgEighteenFile,
			@RequestParam("imgNineteenFile") MultipartFile imgNineteenFile, @RequestParam("imgTwentyFile") MultipartFile imgTwentyFile) {
		try {
			// 上传图片
			String path = ConfigUtil.get("file.upload.path") + Const.UPLOAD_PATH_PRODUCT;
			String newFileName = null;
			int type = 0;
			String fileName = null;
			String ext = null;
			int size = 0;// 图片大小
			String contentType = null;
			Date now = new Date();
			Files filesRecord = null;
			// 展示图
			if (!imgLogoFile.isEmpty()) {
				fileName = imgLogoFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgLogoFile.getSize();
				contentType = imgLogoFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgLogoFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgLogo() != null) {
					filesRecord.setId(product.getImgLogo());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgLogo(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片1
			if (!imgOneFile.isEmpty()) {
				fileName = imgOneFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgOneFile.getSize();
				contentType = imgOneFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgOneFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgOne() != null) {
					filesRecord.setId(product.getImgOne());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgOne(filesService.insertAndReturnPK(filesRecord));
			}

			// 图片2
			if (!imgTwoFile.isEmpty()) {
				fileName = imgTwoFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgTwoFile.getSize();
				contentType = imgTwoFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgTwoFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgTwo() != null) {
					filesRecord.setId(product.getImgTwo());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgTwo(filesService.insertAndReturnPK(filesRecord));
			}

			// 图片3
			if (!imgThreeFile.isEmpty()) {
				fileName = imgThreeFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgThreeFile.getSize();
				contentType = imgThreeFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgThreeFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgThree() != null) {
					filesRecord.setId(product.getImgThree());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgThree(filesService.insertAndReturnPK(filesRecord));
			}

			// 图片4
			if (!imgFourFile.isEmpty()) {
				fileName = imgFourFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgFourFile.getSize();
				contentType = imgFourFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgFourFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgFour() != null) {
					filesRecord.setId(product.getImgFour());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgFour(filesService.insertAndReturnPK(filesRecord));
			}

			// 图片5
			if (!imgFiveFile.isEmpty()) {
				fileName = imgFiveFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgFiveFile.getSize();
				contentType = imgFiveFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgFiveFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgFive() != null) {
					filesRecord.setId(product.getImgFive());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgFive(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片6
			if (!imgSixFile.isEmpty()) {
				fileName = imgSixFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgSixFile.getSize();
				contentType = imgSixFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgSixFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgSix() != null) {
					filesRecord.setId(product.getImgSix());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgSix(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片7
			if (!imgSevenFile.isEmpty()) {
				fileName = imgSevenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgSevenFile.getSize();
				contentType = imgSevenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgSevenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgSeven() != null) {
					filesRecord.setId(product.getImgSeven());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgSeven(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片8
			if (!imgEightFile.isEmpty()) {
				fileName = imgEightFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgEightFile.getSize();
				contentType = imgEightFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgEightFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgEight() != null) {
					filesRecord.setId(product.getImgEight());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgEight(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片9
			if (!imgNineFile.isEmpty()) {
				fileName = imgNineFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgNineFile.getSize();
				contentType = imgNineFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgNineFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgNine() != null) {
					filesRecord.setId(product.getImgNine());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgNine(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片10
			if (!imgTenFile.isEmpty()) {
				fileName = imgTenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgTenFile.getSize();
				contentType = imgTenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgTenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgTen() != null) {
					filesRecord.setId(product.getImgTen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgTen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片11
			if (!imgElevenFile.isEmpty()) {
				fileName = imgElevenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgElevenFile.getSize();
				contentType = imgElevenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgElevenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgEleven() != null) {
					filesRecord.setId(product.getImgEleven());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgEleven(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片11
			if (!imgTwelveFile.isEmpty()) {
				fileName = imgTwelveFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgTwelveFile.getSize();
				contentType = imgTwelveFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgTwelveFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgTwelve() != null) {
					filesRecord.setId(product.getImgTwelve());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgTwelve(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片13
			if (!imgThirteenFile.isEmpty()) {
				fileName = imgThirteenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgThirteenFile.getSize();
				contentType = imgThirteenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgThirteenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgThirteen() != null) {
					filesRecord.setId(product.getImgThirteen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgThirteen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片14
			if (!imgFourteenFile.isEmpty()) {
				fileName = imgFourteenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgFourteenFile.getSize();
				contentType = imgFourteenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgFourteenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgFourteen() != null) {
					filesRecord.setId(product.getImgFourteen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgFourteen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片15
			if (!imgFifteenFile.isEmpty()) {
				fileName = imgFifteenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgFifteenFile.getSize();
				contentType = imgFifteenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgFifteenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgFifteen() != null) {
					filesRecord.setId(product.getImgFifteen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgFifteen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片16
			if (!imgSixteenFile.isEmpty()) {
				fileName = imgSixteenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgSixteenFile.getSize();
				contentType = imgSixteenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgSixteenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgSixteen() != null) {
					filesRecord.setId(product.getImgSixteen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgSixteen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片17
			if (!imgSeventeenFile.isEmpty()) {
				fileName = imgSeventeenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgSeventeenFile.getSize();
				contentType = imgSeventeenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgSeventeenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgSeventeen() != null) {
					filesRecord.setId(product.getImgSeventeen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgSeventeen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片18
			if (!imgEighteenFile.isEmpty()) {
				fileName = imgEighteenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgEighteenFile.getSize();
				contentType = imgEighteenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgEighteenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgEighteen() != null) {
					filesRecord.setId(product.getImgEighteen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgEighteen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片19
			if (!imgNineteenFile.isEmpty()) {
				fileName = imgNineteenFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgNineteenFile.getSize();
				contentType = imgNineteenFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgNineteenFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgNineteen() != null) {
					filesRecord.setId(product.getImgNineteen());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgNineteen(filesService.insertAndReturnPK(filesRecord));
			}
			// 图片20
			if (!imgTwentyFile.isEmpty()) {
				fileName = imgTwentyFile.getOriginalFilename();
				ext = fileName.substring(fileName.lastIndexOf('.') + 1);
				newFileName = UUID.randomUUID().toString() + "." + ext;
				size = (int) imgTwentyFile.getSize();
				contentType = imgTwentyFile.getContentType();
				File targetFile = new File(path, newFileName);
				if (!targetFile.exists()) {
					targetFile.mkdirs();
				}
				imgTwentyFile.transferTo(targetFile);

				filesRecord = new Files();
				// 删除历史图片
				if (product.getImgTwenty() != null) {
					filesRecord.setId(product.getImgTwenty());
					filesRecord.setStatus(Const.FILES_STATUS_DELETE);
					filesService.updateById(filesRecord);
				}

				filesRecord.setPath(Const.UPLOAD_PATH_PRODUCT + newFileName);
				filesRecord.setType(type);
				filesRecord.setName(fileName);
				filesRecord.setExt(ext);
				filesRecord.setSize(size);
				filesRecord.setContentType(contentType);
				filesRecord.setSort(0);
				filesRecord.setStatus(Const.FILES_STATUS_INIT);
				filesRecord.setCreateTime(now);
				// 插入图片并得到Files.id
				product.setImgTwenty(filesService.insertAndReturnPK(filesRecord));
			}

			String message = ValidatorUtils.validate(product);
			if (StringUtils.isBlank(message)) {
				sort(product);// 重新排序
				if (product.getId() != 0) {
					product.setUpdateTime(now);
					productService.updateById(product);
				} else {
					product.setCreateTime(now);
					product.setUpdateTime(now);
					product.setId(productService.insertAndReturnPK(product));
				}

				WebContext.setAttribute(Const.MSG, "保存成功");
				WebContext.setAttribute("productType", dictService.selectByColumn(Const.PRODUCT_TYPE));
				WebContext.setAttribute("productCategory", productCategoryService.selectCategory(Const.STATUS_ENABLED));
				WebContext.setAttribute("imgLogoPath", FileUtil.getUrl(filesService.selectById(product.getImgLogo())));
				if (product.getImgOne() != null) {
					WebContext.setAttribute("imgOnePath", FileUtil.getUrl(filesService.selectById(product.getImgOne())));
				}
				if (product.getImgTwo() != null) {
					WebContext.setAttribute("imgTwoPath", FileUtil.getUrl(filesService.selectById(product.getImgTwo())));
				}
				if (product.getImgThree() != null) {
					WebContext.setAttribute("imgThreePath", FileUtil.getUrl(filesService.selectById(product.getImgThree())));
				}
				if (product.getImgFour() != null) {
					WebContext.setAttribute("imgFourPath", FileUtil.getUrl(filesService.selectById(product.getImgFour())));
				}
				if (product.getImgFive() != null) {
					WebContext.setAttribute("imgFivePath", FileUtil.getUrl(filesService.selectById(product.getImgFive())));
				}
				if (product.getImgSix() != null) {
					WebContext.setAttribute("imgSixPath", FileUtil.getUrl(filesService.selectById(product.getImgSix())));
				}
				if (product.getImgSeven() != null) {
					WebContext.setAttribute("imgSevenPath", FileUtil.getUrl(filesService.selectById(product.getImgSeven())));
				}
				if (product.getImgEight() != null) {
					WebContext.setAttribute("imgEightPath", FileUtil.getUrl(filesService.selectById(product.getImgEight())));
				}
				if (product.getImgNine() != null) {
					WebContext.setAttribute("imgNinePath", FileUtil.getUrl(filesService.selectById(product.getImgNine())));
				}
				if (product.getImgTen() != null) {
					WebContext.setAttribute("imgTenPath", FileUtil.getUrl(filesService.selectById(product.getImgTen())));
				}
				if (product.getImgEleven() != null) {
					WebContext.setAttribute("imgElevenPath", FileUtil.getUrl(filesService.selectById(product.getImgEleven())));
				}
				if (product.getImgTwelve() != null) {
					WebContext.setAttribute("imgTwelvePath", FileUtil.getUrl(filesService.selectById(product.getImgTwelve())));
				}
				if (product.getImgThirteen() != null) {
					WebContext.setAttribute("imgThirteenPath", FileUtil.getUrl(filesService.selectById(product.getImgThirteen())));
				}
				if (product.getImgFourteen() != null) {
					WebContext.setAttribute("imgFourteenPath", FileUtil.getUrl(filesService.selectById(product.getImgFourteen())));
				}
				if (product.getImgFifteen() != null) {
					WebContext.setAttribute("imgFifteenPath", FileUtil.getUrl(filesService.selectById(product.getImgFifteen())));
				}
				if (product.getImgSixteen() != null) {
					WebContext.setAttribute("imgSixteenPath", FileUtil.getUrl(filesService.selectById(product.getImgSixteen())));
				}
				if (product.getImgSeventeen() != null) {
					WebContext.setAttribute("imgSeventeenPath", FileUtil.getUrl(filesService.selectById(product.getImgSeventeen())));
				}
				if (product.getImgEighteen() != null) {
					WebContext.setAttribute("imgEighteenPath", FileUtil.getUrl(filesService.selectById(product.getImgEighteen())));
				}
				if (product.getImgNineteen() != null) {
					WebContext.setAttribute("imgNineteenPath", FileUtil.getUrl(filesService.selectById(product.getImgNineteen())));
				}
				if (product.getImgTwenty() != null) {
					WebContext.setAttribute("imgTwentyPath", FileUtil.getUrl(filesService.selectById(product.getImgTwenty())));
				}
			} else {
				WebContext.setAttribute(Const.MSG, message);
			}
		} catch (Exception e) {
			logger.error("保存失败", e);
			WebContext.setAttribute(Const.MSG, "保存失败");
		}
		return "/front/productAdd";
	}

	/**
	 * 删除产品
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Object delete(@RequestParam Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(Const.STATUS, -1);
		Product record = productService.selectById(id);
		if (record == null) {
			map.put(Const.MSG, "未查到产品信息");
			return map;
		}

		List<Integer> filesIds = new ArrayList<Integer>();
		if (record.getImgOne() != null) {
			filesIds.add(record.getImgOne());
		}
		if (record.getImgTwo() != null) {
			filesIds.add(record.getImgTwo());
		}
		if (record.getImgThree() != null) {
			filesIds.add(record.getImgThree());
		}
		if (record.getImgFour() != null) {
			filesIds.add(record.getImgFour());
		}
		if (record.getImgFive() != null) {
			filesIds.add(record.getImgFive());
		}
		if (record.getImgSix() != null) {
			filesIds.add(record.getImgSix());
		}
		if (record.getImgSeven() != null) {
			filesIds.add(record.getImgSeven());
		}
		if (record.getImgEight() != null) {
			filesIds.add(record.getImgEight());
		}
		if (record.getImgNine() != null) {
			filesIds.add(record.getImgNine());
		}
		if (record.getImgTen() != null) {
			filesIds.add(record.getImgTen());
		}
		if (record.getImgEleven() != null) {
			filesIds.add(record.getImgEleven());
		}
		if (record.getImgTwelve() != null) {
			filesIds.add(record.getImgTwelve());
		}
		if (record.getImgThirteen() != null) {
			filesIds.add(record.getImgThirteen());
		}
		if (record.getImgFourteen() != null) {
			filesIds.add(record.getImgFourteen());
		}
		if (record.getImgFifteen() != null) {
			filesIds.add(record.getImgFifteen());
		}
		if (record.getImgSixteen() != null) {
			filesIds.add(record.getImgSixteen());
		}
		if (record.getImgSeventeen() != null) {
			filesIds.add(record.getImgSeventeen());
		}
		if (record.getImgEighteen() != null) {
			filesIds.add(record.getImgEighteen());
		}
		if (record.getImgNineteen() != null) {
			filesIds.add(record.getImgNineteen());
		}
		if (record.getImgTwenty() != null) {
			filesIds.add(record.getImgTwenty());
		}

		// 删除产品上传文件
		if (!filesIds.isEmpty()) {
			filesService.updateStatusByIds(filesIds, Const.FILES_STATUS_DELETE);
		}
		// 删除产品
		productService.deleteById(id);
		map.put(Const.STATUS, 0);
		return map;
	}

	/**
	 * 删除图片
	 * 
	 * @param id
	 * @param type
	 * @return
	 */
	@RequestMapping("/deleteImg")
	@ResponseBody
	public Object deleteImg(@RequestParam Integer id, @RequestParam Integer fileId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(Const.STATUS, -1);
		if (id == null || fileId == null) {
			map.put(Const.MSG, "参数异常");
			return map;
		}
		Product record = productService.selectById(id);
		if (record == null) {
			map.put(Const.MSG, "未查到产品信息");
			return map;
		}

		if (fileId.equals(record.getImgOne())) {
			record.setImgOne(null);
			record.setIsMbOne(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgTwo())) {
			record.setImgTwo(null);
			record.setIsMbTwo(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgThree())) {
			record.setImgThree(null);
			record.setIsMbThree(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgFour())) {
			record.setImgFour(null);
			record.setIsMbFour(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgFive())) {
			record.setImgFive(null);
			record.setIsMbFive(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgSix())) {
			record.setImgSix(null);
			record.setIsMbSix(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgSeven())) {
			record.setImgSeven(null);
			record.setIsMbSeven(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgEight())) {
			record.setImgEight(null);
			record.setIsMbEight(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgNine())) {
			record.setImgNine(null);
			record.setIsMbNine(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgTen())) {
			record.setImgTen(null);
			record.setIsMbTen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgEleven())) {
			record.setImgEleven(null);
			record.setIsMbEleven(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgTwelve())) {
			record.setImgTwelve(null);
			record.setIsMbTwelve(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgThirteen())) {
			record.setImgThirteen(null);
			record.setIsMbThirteen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgFourteen())) {
			record.setImgFourteen(null);
			record.setIsMbFourteen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgFifteen())) {
			record.setImgFifteen(null);
			record.setIsMbFifteen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgSixteen())) {
			record.setImgSixteen(null);
			record.setIsMbSixteen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgSeventeen())) {
			record.setImgSeventeen(null);
			record.setIsMbSeventeen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgEighteen())) {
			record.setImgEighteen(null);
			record.setIsMbEighteen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgNineteen())) {
			record.setImgNineteen(null);
			record.setIsMbNineteen(Const.STATUS_NO);
		} else if (fileId.equals(record.getImgTwenty())) {
			record.setImgTwenty(null);
			record.setIsMbTwenty(Const.STATUS_NO);
		} else {
			map.put(Const.MSG, "删除失败,fileId不存在");
			return map;
		}
		sort(record);// 重新排序
		record.setUpdateTime(new Date());
		int i = productService.update(record);
		if (i > 0) {
			filesService.updateStatusByIds(Arrays.asList(fileId), Const.FILES_STATUS_DELETE);// 删除轮播图
			map.put(Const.STATUS, 0);
		} else {
			map.put(Const.MSG, "删除失败");
		}
		return map;
	}

	private void sort(Product product) {
		List<Integer> fIds = new ArrayList<Integer>();
		fIds.add(product.getImgOne());
		fIds.add(product.getImgTwo());
		fIds.add(product.getImgThree());
		fIds.add(product.getImgFour());
		fIds.add(product.getImgFive());
		fIds.add(product.getImgSix());
		fIds.add(product.getImgSeven());
		fIds.add(product.getImgEight());
		fIds.add(product.getImgNine());
		fIds.add(product.getImgTen());
		fIds.add(product.getImgEleven());
		fIds.add(product.getImgTwelve());
		fIds.add(product.getImgThirteen());
		fIds.add(product.getImgFourteen());
		fIds.add(product.getImgFifteen());
		fIds.add(product.getImgSixteen());
		fIds.add(product.getImgSeventeen());
		fIds.add(product.getImgEighteen());
		fIds.add(product.getImgNineteen());
		fIds.add(product.getImgTwenty());
		Iterator<Integer> it = fIds.iterator();
		while (it.hasNext()) {
			if (it.next() == null) {
				it.remove();
			}
		}
		product.setImgOne(fIds.size() > 0 ? fIds.get(0) : null);
		product.setImgTwo(fIds.size() > 1 ? fIds.get(1) : null);
		product.setImgThree(fIds.size() > 2 ? fIds.get(2) : null);
		product.setImgFour(fIds.size() > 3 ? fIds.get(3) : null);
		product.setImgFive(fIds.size() > 4 ? fIds.get(4) : null);
		product.setImgSix(fIds.size() > 5 ? fIds.get(5) : null);
		product.setImgSeven(fIds.size() > 6 ? fIds.get(6) : null);
		product.setImgEight(fIds.size() > 7 ? fIds.get(7) : null);
		product.setImgNine(fIds.size() > 8 ? fIds.get(8) : null);
		product.setImgTen(fIds.size() > 9 ? fIds.get(9) : null);
		product.setImgEleven(fIds.size() > 10 ? fIds.get(10) : null);
		product.setImgTwelve(fIds.size() > 11 ? fIds.get(11) : null);
		product.setImgThirteen(fIds.size() > 12 ? fIds.get(12) : null);
		product.setImgFourteen(fIds.size() > 13 ? fIds.get(13) : null);
		product.setImgFifteen(fIds.size() > 14 ? fIds.get(14) : null);
		product.setImgSixteen(fIds.size() > 15 ? fIds.get(15) : null);
		product.setImgSeventeen(fIds.size() > 16 ? fIds.get(16) : null);
		product.setImgEighteen(fIds.size() > 17 ? fIds.get(17) : null);
		product.setImgNineteen(fIds.size() > 18 ? fIds.get(18) : null);
		product.setImgTwenty(fIds.size() > 19 ? fIds.get(19) : null);
	}
}
